package com.epoint.juc.lock;

public class synchronizedDemo {

    public static void main(String[] args) {
        Ticket ticket = new Ticket();

        new Thread(() -> {
            for(int i = 0; i < 50; i ++){
                ticket.sell();
            }
        }, "1").start();
        new Thread(() -> {
            for(int i = 0; i < 50; i ++){
                ticket.sell();
            }
        }, "2").start();
    }
}

class Ticket{
    private int count = 100;

    public synchronized void sell(){
        System.out.println(Thread.currentThread().getName() + "，当前剩余数量：" + count--);
    }
}
